﻿using System.Web.UI;

namespace Eneta.Portal.Events
{
    public static class Utility
    {
        public static Control FindControl(this Control control, string name, bool recursive)
        {
            if (!recursive)
            {
                return control.FindControl(name);
            }

            foreach (Control child in control.Controls)
            {
                if (child.ID == name)
                {
                    return child;
                }

                var ctl = child.FindControl(name, recursive);
                if (ctl != null)
                {
                    return ctl;
                }
            }

            return null;
        }

        public static object Iif(this Control control, bool condition, object trueResult, object falseResult)
        {
            return condition ? trueResult : falseResult;
        }
    }
}
